from enum import Enum
import os
import pathlib

from app.schemas.risk_schema import FeeRiskSchema

class BaseConfig:
    RUN_ENV = 'local'
    BASE_DIR: pathlib.Path = pathlib.Path(__file__).parent.parent

    ############### 基础配置 ################
    FILES_DIR = os.environ.get('FILES_DIR') or './tmp'
    LOG_DIR = os.environ.get('LOG_DIR') or os.path.join(FILES_DIR, 'logs')
    if not os.path.exists(FILES_DIR):
        os.makedirs(FILES_DIR)
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)
    LOG_LEVEL = os.environ.get('LOG_LEVEL') or 'debug'

    STATIC_PATH = 'static'
    UPLOAD_PATH = '%s/upload' % FILES_DIR

    
    # database
    DB_HOST = os.environ.get('XP_DB_HOST') or 'localhost'
    DB_NAME = os.environ.get('XP_DB_NAME') or 'newpay_dev'
    DB_USER = os.environ.get('XP_DB_USER') or 'foo'
    DB_PASS = os.environ.get('XP_DB_PASS') or '123456'

    SQLALCHEMY_DATABASE_URL = "mysql+pymysql://%s:%s@%s/%s?charset=utf8mb4" % (
        DB_USER,
        DB_PASS,
        DB_HOST,
        DB_NAME
    )

    # redis
    REDIS_HOST = os.environ.get('XP_REDIS_HOST') or 'localhost'
    REDIS_PORT = os.environ.get('XP_REDIS_PORT') or 6379
    REDIS_PASS = os.environ.get('XP_REDIS_PASS') or 'xxx'
    REDIS_DB = os.environ.get('XP_REDIS_DB') or 2


    ############### 安全配置 ################
    SM_PRI_KEY = os.environ.get('SM_PRI_KEY') or '774762c4df0e4097453a3ee35de4b81c7fa9a5d901cf97270159743c37470a3d'
    SM_PUB_KEY = os.environ.get('SM_PUB_KEY') or '04577c5860260ef9f897e6b0276ce0a43f01eee6e918be613197b8ac71d7b66899ea1d5f748f80f6ffae2a0ffa4554deb4f3da362bc7035a711f56aba45a96ee99'
    SECRET_KEY = os.environ.get('SECRET_KEY') or '8a81609a885ae99a70f399548f34c2f5'


    LIMIT_TRANS_AMOUNT = os.environ.get('LIMIT_TRANS_AMOUNT') or 2
    LIMIT_DAY_AMOUNT = os.environ.get('LIMIT_DAY_AMOUNT') or 3
    LIMIT_MONTH_AMOUNT = os.environ.get('LIMIT_MONTH_AMOUNT') or 5

    ORIGINS = [
        "http://xpay.tangyu.com",
    ]

    UNAUTH_URIS = [
        '/login',
        '/prjName'
    ]

    ALLOWED_URIS = [
        '/api/*'
    ]

    ALLOWED_HOSTS = [
        'localhost',
        '172.17.0.1'
    ]

    RISK_CONF = {
        'fee': {
            'max': {
                'mode1': 10000,  # 单笔最高100元
                'mode2': 500    # 比例最高5%
            }
        }
    }

    FEE_RISK_CONF: FeeRiskSchema = FeeRiskSchema(
        g_mode1_max=1000,
        g_mode2_max=500,
        g_mode1_min=0,
        g_mode2_min=0,
    )

    VALIDATE_ACCMOUNT_SIGN = True   # 校验金额签名

    ############### 交易配置 ################

    SERVCIE_URLS = {
        'job-api': os.environ.get('JOB_API_URL') or 'http://localhost:8090',
        'job-process-center': os.environ.get('JOB_PROCESS_CENTER_URL') or 'http://localhost:8005',
        'risk-center': os.environ.get('RISK_CENTER_URL') or 'http://localhost:8003',
        'account-center': os.environ.get('ACCOUNT_CENTER_URL') or 'http://localhost:8002',
        'daifu-fe-pf': os.environ.get('DAIFU_FE_PUFA_URL') or 'http://localhost:3000',
    }


    PAY_CHANNEL_CONFIG = {
        'PF_DAIFU': {
            'service': 'daifu-fe-pf',
            'desc': '浦发代付',
            'pay_type': 3,
            'api_url': SERVCIE_URLS.get('daifu-fe-pf'),
            'bank_code': 'SPDB'
        }
    }

    # 前置配置
    '''
    class FrontEnum(Enum):
        "前置枚举配置"
        DAIFU_PUFA = ('daifu-fe-pf', SERVCIE_URLS.get('daifu-fe-pf'), '浦发代付')
        WX_SCAN = ('wx-scan', 'http://localhost:3000', '微信扫码')
    '''

'''
class ServiceEnum(Enum):
    "服务枚举配置"
    ACCOUNT_CENTER = ('account-center', SERVCIE_URLS.get('account-center'), '账户中心'),
    DAIFU_PUFA = ('daifu-fe-pf', SERVCIE_URLS.get('daifu-fe-pf'), '浦发代付'),
    WX_SCAN = ('wx-scan', 'http://localhost:3000', '微信扫码')
'''

